<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>发票九宫格</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
  <style>
    .grid-container {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 15px;
      margin-top: 20px;
    }
    .grid-item {
      border: 1px solid #ddd;
      border-radius: 5px;
      padding: 10px;
      text-align: center;
    }
    .invoice-image {
      max-width: 100%;
      max-height: 200px;
      margin-bottom: 10px;
    }
    .invoice-info {
      font-size: 0.9em;
    }
  </style>
</head>
<body>
<div class="container mt-4">
  <h1 class="mb-4">发票九宫格</h1>

  <div class="mb-3">
    <a href="/" class="btn btn-primary">返回列表</a>
    <form id="downloadForm" method="post" action="/download-grid" class="d-inline">
      <input type="hidden" name="selectedIds" th:each="invoice : ${invoices}"
             th:value="${invoice.id}">
      <button type="submit" class="btn btn-success">下载九宫格</button>
      <button type="button" class="btn btn-secondary" onclick="window.print()">打印</button>
    </form>
  </div>

  <div class="grid-container">
    <div th:each="invoice : ${invoices}" class="grid-item">
      <a th:href="@{/view-invoice/{fileName}(fileName=${invoice.filePath})}" target="_blank">
        <img th:src="@{/thumbnails/thumbnail_{fileName}(fileName=${invoice.filePath})}"
             class="invoice-image" th:alt="${invoice.invoiceNumber}">
      </a>
      <div class="invoice-info">
        <p><strong>发票号:</strong> <span th:text="${invoice.invoiceNumber}"></span></p>
        <p><strong>金额:</strong> <span th:text="${invoice.amount}"></span></p>
        <p><strong>日期:</strong> <span th:text="${invoice.date}"></span></p>
      </div>
    </div>
  </div>
</div>
</body>
</html>
